layui.use(['form', 'layer', 'table', 'laydate', 'func'], function () {
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var func = layui.func;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    /**
     * 初始化表格
     */
    var UserGoldLog = {
        tableId: "UserGoldLogTable" //表格id
    };

    /**
     * 初始化表格的列
     */
    UserGoldLog.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'puName', align: "center", sort: true, title: '用户名'},
            {field: 'mbtName', align: "center", sort: true, title: '魔盒类型',
                templet: function(object){
                    if('' == object.mbtName || null == object.mbtName || undefined == object.mbtName){
                        return '-';
                    }else{
                        return object.mbtName
                    }
                }
            },
            {field: 'changeType', align: "center", sort: true, title: '变动类型',
                templet: function(object){
                    if(0 == object.changeType){
                        return '<span class="layui-badge layui-bg-green">增加</span>';
                    }else if(1 == object.changeType){
                        return '<span class="layui-badge layui-bg-blue">减少</span>';
                    }
                }
            },
            {field: 'changeNum', align: "center", sort: true, title: "变动值"},
            {field: 'beforeNum', align: "center", sort: true, title: "变动前"},
            {field: 'afterNum', align: "center", sort: true, title: '变动后'},
            {field: 'type', align: "center", sort: true, title: '变动分类',
                templet: function(object){
                    if(0 == object.type){
                        return '<span class="layui-badge layui-bg-green">打卡奖励</span>';
                    }else if(1 == object.type){
                        return '<span class="layui-badge layui-bg-blue">兑换魔盒</span>';
                    }else if(2 == object.type){
                        return '<span class="layui-badge">系统修改</span>';
                    }
                }
            },
            {field: 'reson', align: "center", sort: true, title: '修改原因',
                templet: function(object){
                    if('' == object.reson || null == object.reson || undefined == object.reson){
                        return '-';
                    }else{
                        return object.reson;
                    }
                }
            },
            {field: 'suName', align: "center", sort: true, title: '修改人',
                templet: function(object){
                    if('' == object.suName || null == object.suName || undefined == object.suName){
                        return '-';
                    }else{
                        return object.suName;
                    }
                }
            },
            {field: 'createDate', align: "center", sort: true, title: '时间'}
        ]];
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + UserGoldLog.tableId,
        url: Feng.ctxPath + '/web/userGoldLog/list',
        page: true,
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        height: "full-98",
        cellMinWidth: 100,
        cols: UserGoldLog.initColumn()
    });

    //日期范围
    laydate.render({
        elem: '#createDate'
        ,range: true
    });

    /**
     * 点击查询按钮
     */
    UserGoldLog.search = function () {
        var queryData = {};
        queryData['puName'] = $("#puName").val();
        queryData['suName'] = $("#suName").val();
        queryData['mbtName'] = $("#mbtName").val();
        queryData['changeType'] = $("#changeType").val();
        queryData['type'] = $("#type").val();
        queryData['createDate'] = $("#createDate").val();
        table.reload(UserGoldLog.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    /**
     * 点击重置按钮
     */
    UserGoldLog.reset = function () {
        $("#puName").val("");
        $("#suName").val("");
        $("#mbtName").val("");
        $("#changeType").val("-1");
        $("#type").val("-1");
        $("#createDate").val("");

        form.render();

        var queryData = {};
        queryData['puName'] = "";
        queryData['suName'] = "";
        queryData['mbtName'] = "";
        queryData['changeType'] = "-1";
        queryData['type'] = "-1";
        queryData['createDate'] = "";
        UserGoldLog.search();
    };

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        UserGoldLog.search();
    });

    // 重置按钮点击事件
    $('#btnReset').click(function () {
        UserGoldLog.reset();
    });

    // 工具条点击事件
    // table.on('tool(' + UserGoldLog.tableId + ')', function (obj) {
    //     var data = obj.data;
    //     var layEvent = obj.event;
    //
    //     if (layEvent === 'edit') {
    //         UserGoldLog.onEdit(data);
    //     } else if (layEvent === 'delete') {
    //         UserGoldLog.onDelete(data);
    //     }
    // });

});

$(function () {
    var panehHidden = false;
    if ($(this).width() < 769) {
        panehHidden = true;
    }
    $('#myContiner').layout({initClosed: panehHidden, west__size: 260});
});